/*    
    OpenMheg - A free MHEG-5 library
    Copyright (C) 2008 Dharmesh Malam

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WinForms.Renderer;
using Core.Model.Ingredients.Presentable.Visibles;

namespace WinForms
{
    public partial class ScreenJustMHEG : Form
    {
        public delegate void refreshDelegate ( System.Drawing.Rectangle [] rs, List<Core.Model.Ingredients.Presentable.Visibles.Visible> vs );
        MHEGScreen mhegscreen ;

        public ScreenJustMHEG ()
        {
            InitializeComponent();
            this.SetStyle( ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true );
            mhegscreen = new MHEGScreen( MHEGRenderMode.GDIPlus );
            Control control  = mhegscreen.Panel;
            control.Location = new Point( 0, 0 );
            control.Anchor = AnchorStyles.Left | AnchorStyles.Top;
            control.Dock = DockStyle.Fill;
            this.Controls.Add( control );
            this.Size = new Size( MHEGDisplayConstants.DefaultMHEGPanelSize.Width, MHEGDisplayConstants.DefaultMHEGPanelSize.Height );
        }

        private void Screen_FormClosing ( object sender, FormClosingEventArgs e )
        {
            DisplayControl.Instance.CloseMHEG();
        }

        public  void Refresh ( System.Drawing.Rectangle [] rs, List<Visible> vs )
        {
            if ( mhegscreen != null )
            {

                if ( this.InvokeRequired )
                {
                    this.BeginInvoke( new refreshDelegate( this.Refresh ), new object [] { rs, vs } );
                    return;
                }

                mhegscreen.Refresh( rs, vs, null);
                                
            }

        }

        public void Clear ()
        {
            mhegscreen.Clear();
        }



        private void Screen_Resize ( object sender, EventArgs e )
        {
            mhegscreen.Resize( this.Size );
            mhegscreen.Panel.Size = this.Size;
            
        }

        private void Screen_Move ( object sender, EventArgs e )
        {
            
        }

        private void ScreenJustMHEG_KeyDown ( object sender, KeyEventArgs e )
        {
            DisplayControl.Instance.Remote.DoKey( e );
        }

        private void ScreenJustMHEG_FormClosing(object sender, FormClosingEventArgs e)
        {
            DisplayControl.Instance.CloseJustMHEGFromScreen();
        }
        
    }
}